package org.word.controller;


//插入、快速、冒泡、链表反转、数组变链表、二分、查找丢失数字、查找链表元素、比指定数字大1
public class leetcode {
    public static void main(String[] args) {
            int[] a = {7,5,5,2,6,3,2,1};
            a = maopaoSort(a);
            System.out.println(a);

    }

    //冒泡
    private static int[] maopaoSort(int[] a){
        for (int i = 0; i < a.length-1; i++) {
            for (int j = i+1; j < a.length; j++) {
                if(a[j]<a[i]){
                    int tmp = a[i];
                    a[i] = a[j];
                    a[j]= tmp;
                }
            }
        }
        return a;
    }

    //插入
    private static int[] charuSort(int[] a){
        for (int i = 0; i < a.length; i++) {
            int tmp = a[i];
            for (int j = i-1; j > 0; j--) {
                if(a[i]<a[j]){
                    a[i] = a[j];
                    a[j] = tmp;
                }
            }
        }
        return a;
    }

    //选择
    private static int[] xuanzeSort(int[] a){
        for (int i = 0; i < a.length-1; i++) {
            int min = i;
            for (int j = i+1; j < a.length; j++) {
                if (a[j]<a[min]){
                    min = j;
                }
                if (i!=min){
                    int tmp = a[min];
                    a[min] = a[i];
                    a[i] = tmp;
                }
            }
        }
        return a;
    }

    //常数阶O(1)
    //对数阶O(logN)
    //线性阶O(n)
    //线性对数阶O(nlogN)
    //平方阶O(n²)
    //立方阶O(n³)
    //K次方阶O(n^k)
    //指数阶(2^n)
    //时间:看循环次数
    //空间:看创建的对象随循环次数n的变化不(还是原来的对象就O(1))
}
